﻿using System;
using System.ComponentModel;
using System.Linq;
using NUnit.Framework;
using SharpTestsEx;

namespace AltNetHispano.Vale.Tests
{
	[TestFixture]
	public class DataErrorInfoExampleTest
	{
		public class Customer : IDataErrorInfo
		{
			private readonly IValidator validator;

			public string Name { get; set; }
			public string LastName { get; set; }
			public Customer(IValidator validator)
			{
				this.validator = validator;
			}

			public string this[string columnName]
			{
				get
				{
					var errorMessages = validator.GetInvalidMessages(this, columnName ).ToArray();
					return string.Join(Environment.NewLine, errorMessages);
				}
			}

			public string Error
			{
				get { throw new NotImplementedException(); }
			}
		}

		[Test]
		public void CanGetMessagesForName()
		{
			var validator = new Validator();
			validator.Register<Customer>(p => validator.StringIsRequired("First name", p.Name), p => p.Name);

			var customer = new Customer(validator);

			customer["Name"].Should().Be.EqualTo("First name is required.");
		}

		[Test]
		public void CanGetMessagesForLastName()
		{
			var validator = new Validator();
			validator.Register<Customer>(p => validator.StringIsRequired("First name", p.Name), p => p.Name);

			var customer = new Customer(validator);
			customer["LastName"].Should().Be.Empty();
		}

	}
}